
package com.six.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.six.entity.Product;
import com.six.dao.BannerDaoImpl;
import com.six.dao.CompanyDaoImp;
import com.six.dao.MessageDaoImpl;
import com.six.dao.NewsDaoImpl;
import com.six.dao.ProductDaoImpl;
import com.six.entity.Banner;
import com.six.entity.CompanyInfo;
import com.six.entity.Message;
import com.six.entity.News;

/**
 * 处理主页相关请求
 */
@WebServlet("/HomeServlet")
public class HomeServlet extends BaseServlet {
	/**
	 *   首页
	 *  http://localhost:8080/liuzu/HomeServlet?method=toIndex
	 * @param req
	 * @param resp
	 * @throws ServletException
	 * @throws IOException
	 */
	public void toIndex(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		//调用dao层的方法，获取数据
	    //banner轮播图列表
	    BannerDaoImpl banDao = new BannerDaoImpl();
	    ArrayList<Banner> banList = banDao.getAllList();
	    
	    //推荐的产品列表
	    ProductDaoImpl prodao = new ProductDaoImpl();
	    ArrayList<Product> prolist = prodao.getListLimit6();		
		   
	    
	    //单个公司的信息
	    CompanyDaoImp dao = new CompanyDaoImp();
		CompanyInfo info = dao.getInfo();
	 
		 //推荐的新闻
		NewsDaoImpl newsDao =new NewsDaoImpl();
		ArrayList<News> listLimit4 =newsDao.getAllLimit4();
		
		//存储再作用域中
		req.setAttribute("banList", banList);
		req.setAttribute("proList", prolist);
		req.setAttribute("listLimit4", listLimit4);
		HttpSession session = req.getSession();
		session.setAttribute("info", info);
		
		  //跳转页面
		req.getRequestDispatcher("index.jsp").forward(req, resp);	
		
		


}
	
       public void toMessage(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	
    	// 1.接收客户端传来的参数
   		String name = req.getParameter("username");
   		String tel = req.getParameter("tel");
   		String email = req.getParameter("email");
   		String content = req.getParameter("content");
   		
   		System.out.println("接收的参数是" + name + tel + email + content );
   		
   	// 2.调用dao层的添加方法
   		MessageDaoImpl Message = new MessageDaoImpl();
   		boolean res = Message.insertMessage(new Message(0, name, tel, email, content));
   	// 3.判断结果，实现跳转ת
   		if (res == true) {// 添加成功
   			req.getRequestDispatcher("message.jsp").forward(req, resp);
   		} else {// 添加失败
   			req.setAttribute("res", "// 添加失败");
   			req.getRequestDispatcher("message.jsp").forward(req, resp);
   		}



}}
=======
package com.six.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.six.entity.Product;
import com.six.dao.BannerDaoImpl;
import com.six.dao.CompanyDaoImp;
import com.six.dao.MessageDaoImpl;
import com.six.dao.NewsDaoImpl;
import com.six.dao.ProductDaoImpl;
import com.six.entity.Banner;
import com.six.entity.CompanyInfo;
import com.six.entity.Message;
import com.six.entity.News;

/**
 * ������ҳ�������
 */
@WebServlet("/HomeServlet")
public class HomeServlet extends BaseServlet {
	/**
	 *   ��ҳ
	 *  http://localhost:8080/liuzu/HomeServlet?method=toIndex
	 * @param req
	 * @param resp
	 * @throws ServletException
	 * @throws IOException
	 */
	public void toIndex(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		//����dao��ķ�������ȡ����
	    
	    //banner�ֲ�ͼ�б�
	    BannerDaoImpl banDao = new BannerDaoImpl();
	    ArrayList<Banner> banList = banDao.getAllList();
	    
	        //�Ƽ��Ĳ�Ʒ�б�
	    ProductDaoImpl prodao = new ProductDaoImpl();
	    ArrayList<Product> prolist = prodao.getListLimit6();		
		   
	    
	    //������˾����Ϣ
	    CompanyDaoImp dao = new CompanyDaoImp();
		CompanyInfo info = dao.getInfo();
	 
	    //�Ƽ�������
		NewsDaoImpl newsDao =new NewsDaoImpl();
		ArrayList<News> listLimit4 =newsDao.getAllLimit4();
		
	    //�洢����������
		req.setAttribute("banList", banList);
		req.setAttribute("proList", prolist);
		req.setAttribute("listLimit4", listLimit4);
		HttpSession session = req.getSession();
		session.setAttribute("info", info);
		
	    //��תҳ��
		req.getRequestDispatcher("index.jsp").forward(req, resp);	
		
		


}
	/**
	 * ���԰�
	 * @param req
	 * @param resp
	 * @throws ServletException
	 * @throws IOException
	 */
	
       public void toMessage(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	
    	// 1.���տͻ��˴����Ĳ���
   		String name = req.getParameter("username");
   		String tel = req.getParameter("tel");
   		String email = req.getParameter("email");
   		String content = req.getParameter("content");
   		
   		System.out.println("���յĲ�����" + name + tel + email + content );
   		
   		// 2.����dao�����ӷ���
   		MessageDaoImpl Message = new MessageDaoImpl();
   		boolean res = Message.insertMessage(new Message(0, name, tel, email, content));
   		// 3.�жϽ����ʵ����ת
   		if (res == true) {// ��ӳɹ�
   			req.getRequestDispatcher("message.jsp").forward(req, resp);
   		} else {// ���ʧ��
   			req.setAttribute("res", "���ʧ��");
   			req.getRequestDispatcher("message.jsp").forward(req, resp);
   		}



}}
>>>>>>> branch 'master' of https://gitee.com/jiawenya/liuzu.git
